package com.jeasonzhao.report.model;

import com.jeasonzhao.commons.utils.Algorithms;

public class ReportColumnValue implements java.io.Serializable
{
	private static final long serialVersionUID=1L;
    private ReportColumn m_Column = null;
    private Object m_Value = null;
    private boolean m_isTotalCell = false;
    private boolean m_isMeasure = false;
    public void setTotalCell(boolean b)
    {
        m_isTotalCell = b;
    }

    public ReportColumnValue(ReportColumnValue v)
    {
        if(null != v)
        {
            this.m_Column = v.m_Column;
            this.m_Value = v.m_Value;
            this.m_isTotalCell = v.m_isTotalCell;
            this.m_isMeasure = v.m_isMeasure;
        }
    }

    public static ReportColumnValue totalValue(ReportColumn column)
    {
        ReportColumnValue ret = new ReportColumnValue(column,null);
        ret.m_isTotalCell = true;
        return ret;
    }

    public static ReportColumnValue totalValue(ReportColumn column,Object value)
    {
        ReportColumnValue ret = new ReportColumnValue(column,null);
        ret.m_isTotalCell = true;
        ret.m_Value = value;
        return ret;
    }

    public boolean isNormalCell()
    {
        return false == m_isTotalCell && false == m_isMeasure;
    }

    public static ReportColumnValue measureValue(ReportColumn column)
    {
        ReportColumnValue ret = new ReportColumnValue(column,null);
        ret.m_isMeasure = true;
        return ret;
    }

    public boolean isMeasure()
    {
        return m_isMeasure;
    }

    public boolean isTotalCell()
    {
        return m_isTotalCell;
    }

    public ReportColumnValue(ReportColumn column,Object v)
    {
        m_Column = column;
        m_Value = v;
    }

    public Object getValue()
    {
        return m_Value;
    }

    public ReportColumn getReportColumn()
    {
        return m_Column;
    }

    public int hashCode()
    {
        String str = (null == getReportColumn() ? "" : getReportColumn().getTitle()) +
            (m_isMeasure ? "[Measure]" : "") +
            (m_isTotalCell && null == getValue() ? "[Total]" : "") +
            "=" + getValue();
        return str.hashCode();
    }

    public String toString()
    {
        return(null == getReportColumn() ? "" : getReportColumn().getTitle()) +
            (m_isMeasure ? "[Measure]" : "") +
            (m_isTotalCell ? "[Total]" : "") +
            "=" + getValue();
    }

    public boolean equals(Object obj)
    {
        return Algorithms.areEquals(this,obj);
    }

}
